stage.set_axis(100)
stage.create_grid_overlay(10, "grey")
stage.set_background("soccerfield")
ballx = -90
bally = random.randint(-100,100)
# sprite = codesters.Sprite("image", x, y)
ball = codesters.Sprite("soccerball", ballx, bally)
netx = 80
nety = random.randint(-100,100)
# sprite = codesters.Sprite("image", x, y)
net = codesters.Sprite("soccernet", netx, nety)
net.flip_right_left()
#sprite = codesters.Line(x-start, y-start, x-end, y-end, "color")
line = codesters.Line(ballx, bally, netx, nety, "blue")
slopeguess = float(line.ask("What is the slope of this line?"))
rise = nety - bally
run = netx - ballx
slope = rise / run
# sprite = codesters.Text("text", x, y)
sprite = codesters.Text(slope, 0, 30)
newrise = slopeguess*run
end_y = newrise + bally
t = codesters.Teacher()
try:
tval1 = ball.get_x()
tval2 = ball.get_y()
except:
tval1 = "DNE"
tval2 = "DNE"
try:
tval3 = sprite.get_x()
tval4 = sprite.get_y()
except:
tval3 = "DNE"
tval4 = "DNE"
t1 = TestObjective()
t1.add_success(tval1 == netx and tval2 == end_y , "Great Job!")
t1.add_failure(tval1 == end_y and tval2 == netx, "You reversed the coordinates!")
t1.add_failure(tval1 == "DNE" or tval2 == "DNE", "Did you delete the ball?")
t1.add_failure(tval1 != netx, "Did you change the x-coordinate to netx?")
t1.add_failure(tval2 != end_y, "Did you change the y-coordinate to end_y?")
t2 = TestObjective()
t2.add_success(tval3 == 0 and tval4 == 30, "Great Job!")
t2.add_failure(tval3 == 0 and tval4 == 30 and tval1 == ballx and tval2 == bally, "Did you drag out a Glide To command?")
t2.add_failure(tval3 == -100 and tval4 == 50, "Whoops! Did you change the name in front of the Glide To command to ball?")
t2.add_failure(tval3 is netx, "Did you change the name in front of the Glide To command to ball?")
t2.add_failure(tval4 is end_y, "Whoops! Did you change the name in front of the Glide To command to ball?")
tester = TestManager()
tester.add_test_list([t2, t1])
tester.run_tests()
tester.display_first_feedback()
-
Run Code
-
Activity Submitted!
Submit Work
-
Next Activity
-
Stop Running Code
-
Show Chart
-
Show Console
-
Reset Code Editor
-
Codesters How To (opens in a new tab)